package com.derbysoft.synxisadapter.dswitch3.handler.impl;

import com.derbysoft.dswitch.remote.hotel.dto.AbstractRQ;
import com.derbysoft.dswitch.remote.hotel.dto.AbstractRS;
import com.derbysoft.synxisadapter.commons.log.LogDetailPair;
import com.derbysoft.synxisadapter.commons.log.TransactionLogger;
import com.derbysoft.synxisadapter.commons.model.Direction;

import java.util.HashSet;
import java.util.Set;

/**
 * User: jason
 * Date: 2012-11-29
 */
public abstract class AbstractHandler<RQ extends AbstractRQ, RS extends AbstractRS> {

    protected void appendLogDetail(RQ request, RS response) {
        Set<LogDetailPair> logDetails = TransactionLogger.getLogDetails().get();
        if (logDetails == null) {
            logDetails = new HashSet<LogDetailPair>();
            TransactionLogger.getLogDetails().set(logDetails);
        }
        logDetails.add(LogDetailPair.build(request, Direction.FROM_CHANNEL));
        logDetails.add(LogDetailPair.build(response, Direction.TO_CHANNEL));
    }
}
